Hi Flordelis,
I was facing the same problem: trying to mask out the background through glass with complicated shapes (trees...) in the foreground.
In my search I came up with this solution, which is not perfect but did the trick for me:
glass material: in the refraction menu, set 'affect channels' to 'all channels', set refraction color slider to the right (completely white)
add 'background' to your render elements, this can be then be used in postproduction to mask out your background, also through glass
As you can see, it is not the perfect solution since it only seems to work when the refraction color is set to white, but maybe it can be of any help!
Good luck!