fdo#39440 reduce scope of local variables

This addresses some cppcheck warnings.

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