A comparison of the formation and evolution of magnetic flux ropes in solar coronal mass ejections and magnetotail plasmoids