This is a basic example of using Color Picking Technique. For more info you can read this
The basic idea is to create a copy with unique color of object you want to pick, render it on second scene with that color to texture and after that read pixel color from mouse position. This pixel color can be used as an ID.