Pass the tsdb and query variables around, instead of using instance variables.

As only one instance is created in the RpcHandler, the instance variables were being overwritten
in a concurrent situation. By passing them around, we make this thread-safe.
Fixes #306.

(This hasn't undergone much testing, and could do with being verified)