Upon motion made within twenty days after judgment by any party in a civil action or by the defendant in a criminal action, the magistrate who heard the matter or his successor or designee may, upon good cause shown, set aside judgment and order a new trial. All parties shall be given notice of such motion and an opportunity to be heard.