A variational formulation of the BDF2 method for metric gradient flows