Variable timestep algorithm for molecular dynamics simulation of non-equilibrium processes