I couldn't solve the above problem so I use a global variable now (I guess in my case its good enough since the function will probably be used relative rarely instead of multiple calls within the same time window).