fdo#39440 reduce scope of local variables

This addresses some cppcheck warnings.

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