JNI: Fix stale reference errors
Reusing local references accross JNI calls is no longer allowed
in recent versions of Android.