How to select optimal threshold which separate different classes?

I have trained a network to find the similarity between two images. The test dataset contain equal number of similar and dissimilar samples. Each class has approx. 13822 samples.

I tried different threshold, for example, in the last layer of the network I used sigmoid activation function therefore the output is between [0,1].

I tested threshold such as from 0.5 to 0.9 (for example, if the prediction score is greater then 0.5/0.6/,....,/0.9, consider it as positive sample else negative sample).

Based on this strategy I got the following results:

Threshold   TP  TN  FP  FN  Accuracy    Precision   Recall  F1
0.5 --> 12570   13804   18  1252    0.95    1.00    0.91    0.95
0.6 --> 12115   13813   9   1707    0.94    1.00    0.88    0.93
0.7 --> 11451   13819   3   2371    0.91    1.00    0.83    0.91
0.8 --> 10124   13822   0   3698    0.87    1.00    0.73    0.85
0.9 --> 5132    13822   0   8690    0.69    1.00    0.37    0.54


What I am interested in is to find the optimal threshold based on some method which separates positive and negative classes.