There's a pre-made RealSense component called the Touchless Controller that acts as a mouse replacement that may do this for you without you having to write your own custom system. You can find a test demo for it in the Sample Browser application that came packaged with the SDK.
The Sample Browser is in a folder called 'Intel RealSense SDK Gold' that is placed on the desktop when you install the SDK. You can find the Touchless Controller easily by clicking on the 'SR300 Samples' tab in the Browser.
The source files for the sample program can be found by clicking on the 'Sources' button in the Browser beside the Touchless Controller entry.
And here is the SDK documentation entry for the Touchless Controller.
Please bear in mind that if you want to use the Touchless Controller then you will need to use the '2016 R2' version of the RealSense SDK, as it has been removed from the current R3 SDK version.