Separation and recovery of carbon dioxide by a membrane flash process