fdo#39440 reduce scope of local variables

This addresses some cppcheck warnings.

Change-Id: I09fa7d6f87a73a2ecee9b84e792d5df82ca5b420
Reviewed-on: https://gerrit.libreoffice.org/13457
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>