We describe various properties and give several characterizations of ternary groups satisfying two axioms derived from the third Reidemeister move in knot theory. Using special attributes of such ternary groups, such as semi-commutativity, we construct a ternary invariant of curves immersed in compact surfaces, considered up to flat Reidemeister moves.