Magistrates to get more powers to jail defendants for longer