Coevolution of metallicity and star formation in galaxies to z sime 3.7 - I. A Fundamental Plane