The prosecuting attorney, with the permission of the court, may at any time before the case is finally submitted to the jury dismiss the indictment as to all or a part of the defendants and the dismissal shall not bar a future prosecution for the same offense.