I do not understand why you need data as a global variable. Can't you make it local to drawKinectPointCloud ?