fdo#39440 reduce scope of local variables

This addresses some cppcheck warnings.

Change-Id: I19d0070c5dc54c605a7924b750eee1538bed16b3
Reviewed-on: https://gerrit.libreoffice.org/13384
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>