Measuring optical nonlinearities using a heterodyne Z-Scan technique