Image compression is one of important technologies in the fields of image processing. JPEG has been commonly used for image compression. Since JPEG is a lossy compression method, decoded images exhibit visually unwanted noises. A need for techniques for improving the quality of JPEG images remains because there still exist many images compressed by JPEG today. Many methods for improving the quality of JPEG images have been proposed. Among them, a method based on re-application of JPEG, which means compression and decoding, is recognized as one of efficient methods. In our previous study, we improved this method by incorporating an image database and novel distance measures between two images. In this paper, we propose a new distance measure between two images to improve the performance of our previous method. We also show some results of numerical experiments to verify the efficacy of the proposed criterion.