Whenever it shall appear by affidavit that any one is illegally held in custody or restraint, and that there is good reason to believe that such person will be carried out of the jurisdiction of the court or judge before whom the application is made, or will suffer some irreparable injury before compliance with the writ can be enforced, such court or judge may cause a warrant to be issued reciting the facts, and directed to the sheriff or any constable of the county, commanding him or her to take the person thus held in custody or restraint, and forthwith bring him or her before the court or judge to be dealt with according to the law.