Section 17. A surety in a recognizance to keep the peace, or for good behavior, or both, shall have the same authority and right to take and surrender his principal as if he were bail for him in a civil cause; and after such surrender shall be discharged from all liability for any act of the principal subsequent to such surrender which would be a breach of the condition of the recognizance. The person so surrendered may recognize anew with sufficient sureties for the residue of the term, and shall thereupon be discharged.