It is lawful for any party of whom a bond, undertaking, or other obligation is required to agree with his surety for the deposit of any moneys and assets for which such surety is or may be held responsible with a bank, savings bank, or safe deposit or trust company authorized by law to do business as such or other depository approved by the court, if such deposit is otherwise proper, for the safekeeping thereof, and in such manner as to prevent the withdrawal of such moneys and assets or any part thereof, without the written consent of such surety or an order of the court made on such notice to such surety as such court may direct, and such agreement shall not in any manner release or change the liability of the principal or sureties as established by the terms of the bond.